/*
 * Copyright 2008 CSC Consulting Group under the Apache License, 
 * Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at 
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 
 * law or agreed to in writing, software distributed under the License is 
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific language 
 * governing permissions and limitations under the License.
 */
package com.waw.calendar.plugin.action;

import java.util.Map;

import com.jivesoftware.base.User;

import com.waw.calendar.plugin.CalendarConsts;

/**
 * This action class supports the presentation of an individual's Google Calendar.
 * To do that, the action checks to see if the user has configured his/her Google Calendar.
 * This is indicated by the User having an extended property 
 *
 * @author jtremlett
 */
public class ShowCalendarAction extends BaseCalendarAction {

	private static final long serialVersionUID = 1L;

	/**
	 * This execute method checks whether the User's extended property holding the embedded calendar 
	 * is set (CalendarConsts.EMBEDDED_CALENDAR).
	 * If so, it returns SUCCESS which causes the show calendar page to be displayed.
	 * If not, it returns CalendarConsts.CONFIGURE_CALENDAR which causes the configure calendar page to 
	 * be displayed.
	 * 
	 * @see com.jivesoftware.community.action.ViewProfile#execute()
	 */
	public String execute() {
        super.execute();
        
        // check if google.embedded is set.  If not, the calendar needs to be configured.
        User user = this.getUser();
        Map<String,String> properties = user.getProperties();
        String embedded = properties.get(CalendarConsts.EMBEDDED_CALENDAR);
        
        if(embedded == null || embedded.length() == 0) return CalendarConsts.CONFIGURE_CALENDAR;
        this.setEmbedded(embedded);
        return SUCCESS;
    }

}
